import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'home',
        component: () =>
            import ('../views/HomeView.vue')
    }, {
        path: '/register',
        name: 'Register',
        component: () =>
            import ('../views/auth/Register.vue'),
        meta: {
            title: '注册'
        }
    },
    // 登录
    {
        name: 'login',
        path: '/login',
        component: () =>
            import ('../views/auth/Login'),
        meta: {
            title: '登录'
        }
    },
    // 信息发布
    {
        name: "post-create",
        path: "/post/create",
        component: () =>
            import ("../views/post/create"),
        meta: {
            title: "信息发布",
            requireAuth: true
        },
    },
    // 详情
    {
        name: "post-detail",
        path: "/post/:id",
        component: () =>
            import ("../views/post/Detail"),
    },
    {
        path: '/404',
        name: '404',
        component: () =>
            import ('../views/error/404.vue'),
        meta: {
            title: '404-NotFound'
        }
    },
    // 发布
    {
        name: 'post-create',
        path: '/post/create',
        component: () =>
            import ('../views/post/create'),
        meta: {
            title: '信息发布',
            requireAuth: true
        }
    },
    // 用户设置
    {
        name: 'user-setting',
        path: '/member/:username/setting',
        component: () =>
            import ('../views/user/Setting'),
        meta: {
            title: '设置'
        }
    },
    // 用户主页
    {
        name: 'user',
        path: '/member/:username/home',
        component: () =>
            import ('../views/user/Profile'),
        meta: {
            title: '用户主页'
        }
    },
    {
        path: '*',
        redirect: '/404',
        hidden: true
    }
]

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
    routes
})

export default router